var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
	var ds = req.ds;
	ds.getConnection(function(err, conn) {
	  if (err) {
	    console.error('error connecting: ' + err.stack);
	    return;
	  }else
	    console.log('init connection as id ' + conn.threadId);

	  conn.query( 'SELECT id,title,feed ,description as podcasts', function(error, results, fields) {
	  	res.json(results);
	    conn.release();
	  });
	});
});

router.get('/:id', function(req, res, next) {
	var ds = req.ds;
	ds.getConnection(function(err, conn) {
	  if (err) {
	    console.error('error connecting: ' + err.stack);
	    return;
	  }else
	    console.log('init connection as id ' + conn.threadId);

	  conn.query( 'SELECT id,title,feed,description as podcasts where id=?',
	  	[req.params.id] , function(error, results, fields) {
	  	res.json(results);
	    conn.release();
	  });
	});
});

module.exports = router;
